import java.text.SimpleDateFormat;
import java.util.Date;

public class Book {
    private String title;
    private boolean isRented;
    private Date entryDate;
    private Date borrowedDate;
    private Date returnedDate;
    private SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");

    public Book(String title, Date entryDate) {
        this.title = title;
        this.entryDate = entryDate;
        this.isRented = false;
    }

    public String getTitle() {
        return title;
    }

    public boolean isRented() {
        return isRented;
    }

    public void borrow(Date borrowDate) {
        if (!isRented) {
            isRented = true;
            borrowedDate = borrowDate;
            returnedDate = null;
        }
    }

    public void returnBook(Date returnDate) {
        if (isRented) {
            isRented = false;
            returnedDate = returnDate;
        }
    }

    public String getStatus() {
        if (isRented) {
            return "true, borrowed on " + dateFormat.format(borrowedDate);
        } else if (returnedDate != null) {
            return "false, returned on " + dateFormat.format(returnedDate);
        } else {
            return "false, book entry time is " + dateFormat.format(entryDate);
        }
    }

    public static void main(String[] args) throws Exception {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Book book = new Book("The Da Vinci Code", sdf.parse("2002-01-19"));

        System.out.println("Title (should be The Da Vinci Code): " + book.getTitle());
        System.out.println("Rented? (should be false): " + book.getStatus());

        book.borrow(sdf.parse("2020-12-20"));
        System.out.println("Rented? (should be true): " + book.getStatus());

        book.returnBook(sdf.parse("2021-01-20"));
        System.out.println("Rented? (should be false): " + book.getStatus());
    }
}